package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.converter.StringToEnumConverterFactory;
import com.atguigu.lease.web.admin.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.interceptor.AuthenticationAdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
    @Autowired
    private AuthenticationAdminInterceptor authenticationAdminInterceptor;
//    @Autowired
//    private StringToItemTypeConverter stringToItemTypeConverter;
    @Autowired
    private StringToEnumConverterFactory stringToEnumConverterFactory;
//    注册拦截器验证token
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationAdminInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login/**");
    }
//    注册转换器
//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        registry.addConverter(stringToItemTypeConverter);
//    }


    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToEnumConverterFactory);
    }
}
